package com.neusoft.neuiotms.dcom.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.Length;

import com.neusoft.bizcore.web.jpa.model.AbstractAuditModel;
import com.neusoft.bizcore.web.jpa.model.Comment;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@Entity
@Table(name = "neuiot_knowledge")
@org.hibernate.annotations.Table(appliesTo = "neuiot_knowledge", comment = "知识库表")
public class Knowledge extends AbstractAuditModel {
    private static final long serialVersionUID = 7724831428191577877L;

    @NotBlank(message = "知识标题")
    @Length(max = 255, message = "知识标题不能超过{max}位")
    @Column(length = 255, nullable = false)
    @Comment("varchar(255) NOT NULL COMMENT '知识标题'")
    private String title;

    @Lob
    @Column(columnDefinition = "longtext")
    @Comment("longtext COMMENT '内容'")
    private String content;

    @Column(length = 32, nullable = true)
    @Comment("int(32) NULL COMMENT '阅读量'")
    private Integer readingVolume = 0;

    @NotBlank(message = "创建人编码")
    @Length(max = 255, message = "创建人编码不能超过{max}位")
    @Column(length = 255, nullable = false)
    @Comment("varchar(255) NOT NULL COMMENT '创建人编码'")
    private String userCode;

    @Length(max = 255, message = "创建人名称不能超过{max}位")
    @Column(length = 255, nullable = true)
    @Comment("varchar(255) NULL COMMENT '创建人名称'")
    private String userName;

    @Length(max = 255, message = "更新人编码不能超过{max}位")
    @Column(length = 255, nullable = true)
    @Comment("varchar(255) NOT NULL COMMENT '更新人编码'")
    private String updateUserCode;

    @Length(max = 255, message = "更新人名称不能超过{max}位")
    @Column(length = 255, nullable = true)
    @Comment("varchar(255) NULL COMMENT '更新人名称'")
    private String updateUserName;

    @NotNull(message = "知识库类型不能为空")
    @ManyToOne
    private KnowledgeType type;

    /** 附件列表 **/
    @OneToMany(mappedBy = "knowledge", cascade = CascadeType.ALL)
    private List<KnowledgeAttachment> attachment = new ArrayList<>();

    /** 关键字表 **/
    @OneToMany(mappedBy = "knowledge", cascade = CascadeType.ALL)
    private List<KnowledgeKeywords> keywords = new ArrayList<>();

    /** 评价列表 **/
    @OneToMany(mappedBy = "knowledge", cascade = CascadeType.ALL)
    private List<KnowledgeComment> comment = new ArrayList<>();
}
